package com.esteel.settlement.config.pa;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 调用平安接口采用统一的restTemplate的方式来处理
 * @author zhangxiuzhi
 *
 */
@Configuration
public class PaConfig {


	@Autowired
	private ExecutorProperties executorProperties;
	
	@Bean
	public Map<String,ProcesserInfo> processer(){
		return new HashMap<String,ProcesserInfo>();
	}
	

	/**
	 * 调用B2Bic程序的统一类
	 * @return
	 */
	@Bean
	public PaTemplate paTemplate(){
		return new PaTemplate();
	}
	
	/**
	 * 处理平安调用接口的统一入口
	 * @return
	 */
	@Bean
	public PaMessageProcessor paMessageProcessor(){
		return new PaMessageProcessor();
	}
	
	/**
	 * 执行异步处理的线程池
	 * @return
	 */
	@Bean
	public ExecutorService threadPool(){
		return new ThreadPoolExecutor(executorProperties.getCorePoolSize(),executorProperties.getMaximumPoolSize(),executorProperties.getKeepAliveTime(),TimeUnit.MICROSECONDS,new LinkedBlockingQueue<Runnable>());
	}
	
	/**
	 * 获得平安交易报文的快速方法
	 * @return
	 */
	@Bean
	public PacketFactory packetFactory(){
		return new PacketFactory();
	}
}
